<template>
	<view>
		
		<view style="display: inline-flex;align-items: center; margin-top: 40rpx;">
			<view style="font-size: 30rpx;margin-left: 50rpx;">搜索：</view>
			<u--input
					v-model="searchValue"
					placeholder="请输入搜索内容"
					border="none"
					style="width: 400rpx;margin-left: 50rpx;"
			></u--input>
			<u-button @click="searchMeeingButton()"  style="width: 200rpx;background-color: #398ADE;">搜索</u-button>
		</view>
		<view style="height: 80rpx;">
			
		</view>
		<uni-pagination @change="change" show-icon="true" :total="total" :current="current" :pageSize="pageSize"></uni-pagination>
		
		<view style="display: flex;flex-direction: row;margin-top: 40rpx;height: 60rpx;border-radius: 20rpx;border-bottom: 1px solid #DDDDDD;font-size: 20rpx;">
			<view style="margin-left: 70rpx;">名称</view>
			<view  style="margin-left: 290rpx;">房间号</view>
			<view  style="margin-left: 150rpx;">楼栋号</view>
		</view>
		<!-- 表格数据行 -->
		<view v-for="(item,index) in pageList" :key="index" class="meeting" @click="choseMeeting(item.id)">
			<view class="meeting_item"><image src="@/static/tabs/home.png" class="image"></image></view>
			<view class="meeting_item name">{{item.meetingName}}</view>
			<view class="meeting_item room">{{item.room}}</view>
			<view class="meeting_item building">{{item.building}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.getMeetingList()
		},
		data() {
			return {
				searchValue:'',
				meeting:'',
				current: 1,
				total: '',
				pageSize: 10,
				pageList:''
			}
		},
		methods: {
			currentChangePage (list, currentPage) {
			      console.log('list', list)
			      let from = (currentPage - 1) * this.pageSize
			      let to = currentPage * this.pageSize
			      this.pageList  = []
			      for (; from < to; from++) {
			        if (list[from]) {
			          this.pageList.push(list[from])
			        }
			      }
			    },
			change(e) {
				console.log(e)
				this.current = e.current
				this.currentChangePage(this.meeting, this.current)
			},
			handleUnReserved(){
				uni.request({
					url:'/api/meeting/getMeetingList',
					method: 'post',
					header:{
					            'content-type':'application/json;charset=UTF-8'
					        },
					data:{
						currPage:1,
						pageSize:10
					},
					success: (res) => {
						if(res.data.code===200){
							this.meeting = res.data.data
							this.total = res.data.total
							this.currentChangePage(this.meeting, this.current)
						}
					}
				})
			},
			getMeetingList(){
				uni.request({
					url:'/api/meeting/getMeetingList',
					method: 'post',
					header:{
					            'content-type':'application/json;charset=UTF-8'
					        },
					data:{
						currPage:1,
						pageSize:10
					},
					success: (res) => {
						if(res.data.code===200){
							this.meeting = res.data.data
							this.total = res.data.total
							this.currentChangePage(this.meeting, this.current)
						}
					}
				})
			},
			choseMeeting(id){
				uni.request({
					url:'/api/meeting/getMeetingInfoById?meetingId='+id,
					method:'get',
					success(res) {
						uni.navigateTo({
							url:'../meetingInfoSimple/meetingInfoSimple?meeting='+encodeURIComponent(JSON.stringify(res.data.data)),
						})
					},
					fail() {
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '查询出错'
						})
						uni.navigateBack({
							delta:1
						})
					}
				})
				
			},
			searchMeeingButton(){
				if(this.searchValue === ''){
					this.getMeetingList()
				}else{
					// #ifdef H5
					uni.request({
						url:'/api/meeting/getMeetingByBuilding?building='+this.searchValue,
						method: 'get',
						success: (res) => {
							if(res.data.code===200){
								this.meeting = res.data.data
								this.total = res.data.total
								this.currentChangePage(this.meeting, this.current)
							}
						}
					})
					// #endif
					// #ifdef MP-WEIXIN
					uni.request({
						url:'http://localhost:8080/meeting/getMeetingByBuilding?building='+this.searchValue,
						method: 'get',
						success: (res) => {
							if(res.data.code===200){
								this.meeting = res.data.data	
								this.total = res.data.total
								this.currentChangePage(this.meeting, this.current)
							}
						}
					})
					// #endif
				}
				
			},
		}
	}
</script>

<style>
.meeting{
	height: 100rpx;
	border:1px solid #dddddd;
	border-radius: 10rpx;
	margin: 10rpx;
	display: flex;
	flex-direction: row;
	align-items: center;
	background-color: #4d7ac2;
}
.meeting .room{
	margin-left: 170rpx;
}
.meeting .building{
	margin-left: 100rpx;
}
.meeting_item{
	display: inline-flex;
	font-size: 27rpx;
	width: 200rpx;

}
.people{
	margin-left: 20rpx;
}

.image{
	height: 100rpx;
	width: 80rpx;
	opacity: 0.6;
}
</style>
